/**
 * 将枚举转换成下拉框可以用的数据
 * @param enumVal 枚举
 * @returns
 */
export const EnumToDicData = (enumVal: object) => {
  const enumArray = Object.entries(enumVal);
  const arrVal = enumArray.filter(
    (rows: any[]) => typeof rows[1] == "number" && !isNaN(rows[1])
  );
  const list = arrVal.map((rows: any) => {
    return {
      label: rows[0],
      value: rows[1],
    };
  });
  return list;
};

/**
 * 通过枚举以及枚举值推出该枚举值对应的字段
 * @param enumVal 枚举
 * @param value 值
 * @returns
 */
export const EnumToDicText = (enumVal: object, value: number): string => {
  const enumArray = Object.entries(enumVal);
  const arrVal = enumArray.filter(
    (rows: any[]) => typeof rows[1] == "number" && !isNaN(rows[1])
  );
  const list: any = arrVal.map((rows: any) => {
    return {
      label: rows[0],
      value: rows[1],
    };
  });
  const some = list.find((item: any) => item.value === value);
  return some ? some.label : "--";
};
